package main

import (
	"fmt"
	"time"
)

func main() {
	c := make(chan int, 10)

	/*	go func() {
		for i := 0; i < 50; i++ {
			c <- i
			fmt.Println("写入成功哦")
		}
		defer close(c)
	}()*/
	//单向写
	go func(wc chan<- int) {
		for i := 0; i < 50; i++ {
			wc <- i
			fmt.Println("写入成功哦")
		}
		defer close(wc)
	}(c)
	/*	go func() {
		for a := range c {
			fmt.Println("读到的1", a)
		}
	}()*/
	//单向读通道
	go func(rc <-chan int) {
		for {
			//判断管道是否关闭
			a, ok := <-rc
			if ok {
				fmt.Println("读到的2", a)
			} else {
				fmt.Println("管道已经关闭")
			}

		}
	}(c)
	time.Sleep(2 * time.Second)

}
